home *** CD-ROM | disk | FTP | other *** search
/ CD ROM Paradise Collection 4 / CD ROM Paradise Collection 4 1995 Nov.iso / music / dsik_pas.zip / SETUP.PAS < prev    next >
Pascal/Delphi Source File  |  1994-07-28  |  11KB  |  472 lines

  1. (*  setup.c - Digital Sound Interface Kit V1.01a setup program.
  2.  
  3.     Copyright 1993,94 Carlos Hasan
  4. *)
  5.  
  6. {$B-,R-}
  7.  
  8. program SoundSetup;
  9.  
  10. const
  11.   ID_NONE       = 0;
  12.   ID_SB         = 1;
  13.   ID_SB201      = 2;
  14.   ID_SBPRO      = 3;
  15.   ID_SB16       = 4;
  16.   ID_GUS        = 5;
  17.  
  18. type
  19.   DSMCard = record
  20.     ID          : byte;
  21.     Flags       : byte;
  22.     IOAddr      : word;
  23.     IRQNum      : byte;
  24.     DRQNum      : byte;
  25.     MixRate     : word;
  26.   end;
  27.  
  28.  
  29. const
  30.   VideoSeg      = $B800;
  31.   VideoWidth    = 80;
  32.   VideoHeight   = 25;
  33.  
  34. const
  35.   Black        = 0;
  36.   Blue         = 1;
  37.   Green        = 2;
  38.   Cyan         = 3;
  39.   Red          = 4;
  40.   Magenta      = 5;
  41.   Brown        = 6;
  42.   LightGray    = 7;
  43.   DarkGray     = 8;
  44.   LightBlue    = 9;
  45.   LightGreen   = 10;
  46.   LightCyan    = 11;
  47.   LightRed     = 12;
  48.   LightMagenta = 13;
  49.   Yellow       = 14;
  50.   White        = 15;
  51.   Blink        = 128;
  52.  
  53. const
  54.   kbEsc        = $001B;
  55.   kbEnter      = $000D;
  56.   kbUp         = $4800;
  57.   kbDown       = $5000;
  58.  
  59. type
  60.   TFrame = array [0..5] of char;
  61.  
  62.   TMenu = record
  63.     Title  : PChar;
  64.     Option : Word;
  65.     Items  : array [0..7] of PChar;
  66.   end;
  67.  
  68. const
  69.   SingleFrame: TFrame = #218#191#192#217#196#179;
  70.   DoubleFrame: TFrame = #201#187#200#188#205#186;
  71.  
  72.  
  73. procedure SetTextMode; assembler;
  74. asm
  75.         mov     ax,0003h
  76.         int     10h
  77. end;
  78.  
  79. procedure WaitVR; assembler;
  80. asm
  81.         mov     dx,3DAh
  82. @0:     in      al,dx
  83.         test    al,08h
  84.         jne     @0
  85. @1:     in      al,dx
  86.         test    al,08h
  87.         je      @1
  88. end;
  89.  
  90. procedure DrawRect(XLeft,YTop,XRight,YBottom:Integer; C:Char; Color:Byte); assembler;
  91. asm
  92.         push    si
  93.         push    di
  94.         push    ds
  95.         push    es
  96.         mov     ax,VideoSeg
  97.         mov     es,ax
  98.         mov     ax,[Ytop]
  99.         mov     dx,VideoWidth
  100.         mul     dx
  101.         add     ax,[XLeft]
  102.         add     ax,ax
  103.         mov     di,ax
  104.         mov     bx,[XRight]
  105.         sub     bx,[XLeft]
  106.         jl      @0
  107.         mov     dx,[YBottom]
  108.         sub     dx,[YTop]
  109.         jl      @0
  110.         inc     bx
  111.         inc     dx
  112.         mov     al,[C]
  113.         mov     ah,[Color]
  114.         cld
  115. @1:     push    di
  116.         mov     cx,bx
  117.         rep     stosw
  118.         pop     di
  119.         add     di,2*VideoWidth
  120.         dec     dx
  121.         jne     @1
  122. @0:     pop     es
  123.         pop     ds
  124.         pop     di
  125.         pop     si
  126. end;
  127.  
  128. procedure DrawBox(XLeft,YTop,XRight,YBottom:Integer; Frame:PChar; Color:Byte); assembler;
  129. asm
  130.         push    si
  131.         push    di
  132.         push    ds
  133.         push    es
  134.         lds     si,[Frame]
  135.         mov     ax,VideoSeg
  136.         mov     es,ax
  137.         mov     ax,[YTop]
  138.         mov     dx,VideoWidth
  139.         mul     dx
  140.         add     ax,[XLeft]
  141.         add     ax,ax
  142.         mov     di,ax
  143.         mov     bx,[XRight]
  144.         sub     bx,[XLeft]
  145.         dec     bx
  146.         jl      @0
  147.         mov     dx,[YBottom]
  148.         sub     dx,[YTop]
  149.         dec     dx
  150.         jl      @0
  151.         mov     ah,[Color]
  152.         cld
  153.         push    di
  154.         mov     al,[si+0]
  155.         stosw
  156.         mov     al,[si+4]
  157.         mov     cx,bx
  158.         rep     stosw
  159.         mov     al,[si+1]
  160.         stosw
  161.         pop     di
  162.         add     di,2*VideoWidth
  163. @1:     push    di
  164.         mov     al,[si+5]
  165.         stosw
  166.         mov     al,20h
  167.         mov     cx,bx
  168.         rep     stosw
  169.         mov     al,[si+5]
  170.         stosw
  171.         pop     di
  172.         add     di,2*VideoWidth
  173.         dec     dx
  174.         jne     @1
  175.         mov     al,[si+2]
  176.         stosw
  177.         mov     al,[si+4]
  178.         mov     cx,bx
  179.         rep     stosw
  180.         mov     al,[si+3]
  181.         stosw
  182. @0:     pop     es
  183.         pop     ds
  184.         pop     di
  185.         pop     si
  186. end;
  187.  
  188. procedure DrawText(X,Y:Integer; Text:PChar; Color:Byte); assembler;
  189. asm
  190.         push    si
  191.         push    di
  192.         push    ds
  193.         push    es
  194.         lds     si,[Text]
  195.         mov     ax,VideoSeg
  196.         mov     es,ax
  197.         mov     ax,[Y]
  198.         mov     dx,VideoWidth
  199.         mul     dx
  200.         add     ax,[X]
  201.         add     ax,ax
  202.         mov     di,ax
  203.         mov     ah,[Color]
  204. @1:     mov     al,[si]
  205.         inc     si
  206.         test    al,al
  207.         je      @0
  208.         mov     [es:di],ax
  209.         add     di,2
  210.         jmp     @1
  211. @0:     pop     es
  212.         pop     ds
  213.         pop     di
  214.         pop     si
  215. end;
  216.  
  217. function StrLen(S:PChar):Integer; assembler;
  218. asm
  219.         push    di
  220.         push    es
  221.         les     di,[S]
  222.         xor     ax,ax
  223. @1:     mov     dl,[es:di]
  224.         test    dl,dl
  225.         je      @0
  226.         inc     di
  227.         inc     ax
  228.         jne     @1
  229. @0:     pop     es
  230.         pop     di
  231. end;
  232.  
  233. function ReadKey: word; assembler;
  234. asm
  235.         mov     ah,00h
  236.         int     16h
  237.         test    al,al
  238.         je      @0
  239.         xor     ah,ah
  240. @0:
  241. end;
  242.  
  243.  
  244. procedure DrawDesktop;
  245. begin
  246.   DrawRect(0,0,79,24,#178,LightGray);
  247.   DrawBox(0,0,79,2,DoubleFrame,White or Blue shl 4);
  248.   DrawRect(0,24,79,24,#32,White or Blue shl 4);
  249.   DrawText(22,1,'Digital Sound System Setup Program',White or Blue shl 4);
  250.   DrawText(21,24,'Copyright (C) 1993,1994 Carlos Hasan',White or Blue shl 4);
  251. end;
  252.  
  253. procedure DrawMenu(const Menu:TMenu);
  254. var
  255.   I,J,X,Y,Width,Height: Integer;
  256. begin
  257.   Width  := StrLen(Menu.Title);
  258.   Height := 0;
  259.   for I := 0 to 7 do begin
  260.     if Menu.Items[I] = nil then break;
  261.     J := StrLen(Menu.Items[I]);
  262.     if Width < J then Width := J;
  263.     inc(Height);
  264.   end;
  265.   inc(Width,6);
  266.   inc(Height,2);
  267.  
  268.   X := (VideoWidth-Width) shr 1;
  269.   Y := (VideoHeight-Height) shr 1;
  270.   DrawBox(X,Y,X+Width-1,Y+Height-1,SingleFrame,White or Blue shl 4);
  271.   DrawText(X+(Width-StrLen(Menu.Title)) shr 1,Y,Menu.Title,White or Blue shl 4);
  272.  
  273.   for I := 0 to 7 do begin
  274.     if Menu.Items[I] = nil then break;
  275.     J := StrLen(Menu.Items[I]);
  276.     if Menu.Option = I then begin
  277.       DrawRect(X+1,Y+1+I,X+Width-2,Y+1+I,#32,Blue or LightGray shl 4);
  278.       DrawText(X+(Width-J) shr 1,Y+1+I,Menu.Items[I],Blue or LightGray shl 4);
  279.     end
  280.     else begin
  281.       DrawText(X+(Width-J) shr 1,Y+1+I,Menu.Items[I],White or Blue shl 4);
  282.     end;
  283.   end;
  284. end;
  285.  
  286. function DoMenu(var Menu:TMenu): Boolean;
  287. var
  288.   Key,Option : Word;
  289. begin
  290.   Option := Menu.Option;
  291.   repeat
  292.     WaitVR;
  293.     DrawMenu(Menu);
  294.     Key := ReadKey;
  295.     case Key of
  296.       kbUp   : if Menu.Option > 0 then dec(Menu.Option);
  297.       kbDown : if (Menu.Option < 7) and (Menu.Items[Succ(Menu.Option)] <> nil) then inc(Menu.Option);
  298.     end;
  299.   until (Key=kbEsc) or (Key=kbEnter);
  300.   if Key=kbEsc then Menu.Option := Option;
  301.   DoMenu := (Key=kbEsc);
  302. end;
  303.  
  304.  
  305.  
  306. const
  307.   MainMenu : TMenu =
  308.     ( Title  : ' Main Menu ';
  309.       Option : 0;
  310.       Items  : ( 'Select Soundcard',
  311.                  'Save and Exit',
  312.                  nil,
  313.                  nil,
  314.                  nil,
  315.                  nil,
  316.                  nil,
  317.                  nil )
  318.     );
  319.  
  320.   CardMenu : TMenu =
  321.     ( Title  : ' Select Soundcard ';
  322.       Option : 1;
  323.       Items  : ( 'None               ',
  324.                  'Sound Blaster      ',
  325.                  'Sound Blaster 2.01 ',
  326.                  'Sound Blaster Pro  ',
  327.                  'Sound Blaster 16   ',
  328.                  'Gravis Ultrasound  ',
  329.                  nil,
  330.                  nil )
  331.     );
  332.  
  333.   PortMenu : TMenu =
  334.     ( Title  : ' Select I/O Port ';
  335.       Option : 1;
  336.       Items  : ( '210',
  337.                  '220',
  338.                  '230',
  339.                  '240',
  340.                  '250',
  341.                  '260',
  342.                  '270',
  343.                  '280' )
  344.     );
  345.  
  346.   IRQLineMenu : TMenu =
  347.     ( Title  : ' Select IRQ Line ';
  348.       Option : 3;
  349.       Items  : ( 'IRQ 2 ',
  350.                  'IRQ 3 ',
  351.                  'IRQ 5 ',
  352.                  'IRQ 7 ',
  353.                  'IRQ 10',
  354.                  'IRQ 11',
  355.                  'IRQ 12',
  356.                  'IRQ 15' )
  357.     );
  358.  
  359.   DMAChanMenu : TMenu =
  360.     ( Title  : ' Select DMA Channel ';
  361.       Option : 1;
  362.       Items  : ( 'DMA 0',
  363.                  'DMA 1',
  364.                  'DMA 3',
  365.                  nil,
  366.                  nil,
  367.                  nil,
  368.                  nil,
  369.                  nil )
  370.     );
  371.  
  372.   MixRateMenu : TMenu =
  373.     ( Title  : ' Select Mixing Rate ';
  374.       Option : 2;
  375.       Items  : ( ' 8000 Hz',
  376.                  '12000 Hz',
  377.                  '16000 Hz',
  378.                  '20000 hz',
  379.                  '22000 Hz',
  380.                  '28000 Hz',
  381.                  '36000 Hz',
  382.                  '44100 Hz' )
  383.     );
  384.  
  385. var
  386.   SoundCard : DSMCard;
  387.   SoundFile : File;
  388. begin
  389.   SetTextMode;
  390.  
  391.   while true do begin
  392.     DrawDesktop;
  393.     if DoMenu(MainMenu) then begin
  394.       MainMenu.Option := 2;
  395.       break;
  396.     end;
  397.     if MainMenu.Option = 1 then break;
  398.     if DoMenu(CardMenu) then continue;
  399.     if CardMenu.Option = 0 then continue;
  400.     if DoMenu(PortMenu) then continue;
  401.     if DoMenu(IRQLineMenu) then continue;
  402.     if DoMenu(DMAChanMenu) then continue;
  403.     if (CardMenu.Option <> 5) then if DoMenu(MixRateMenu) then continue;
  404.     MainMenu.Option := 1;
  405.   end;
  406.  
  407.   SetTextMode;
  408.  
  409.   if MainMenu.Option = 1 then begin
  410.     case CardMenu.Option of
  411.       0: SoundCard.ID := ID_NONE;
  412.       1: SoundCard.ID := ID_SB;
  413.       2: SoundCard.ID := ID_SB201;
  414.       3: SoundCard.ID := ID_SBPRO;
  415.       4: SoundCard.ID := ID_SB16;
  416.       5: SoundCard.ID := ID_GUS;
  417.     end;
  418.     case PortMenu.Option of
  419.       0: SoundCard.IOAddr := $210;
  420.       1: SoundCard.IOAddr := $220;
  421.       2: SoundCard.IOAddr := $230;
  422.       3: SoundCard.IOAddr := $240;
  423.       4: SoundCard.IOAddr := $250;
  424.       5: SoundCard.IOAddr := $260;
  425.       6: SoundCard.IOAddr := $270;
  426.       7: SoundCard.IOAddr := $280;
  427.     end;
  428.     case IRQLineMenu.Option of
  429.       0: SoundCard.IRQNum := 2;
  430.       1: SoundCard.IRQNum := 3;
  431.       2: SoundCard.IRQNum := 5;
  432.       3: SoundCard.IRQNum := 7;
  433.       4: SoundCard.IRQNum := 10;
  434.       5: SoundCard.IRQNum := 11;
  435.       6: SoundCard.IRQNum := 12;
  436.       7: SoundCard.IRQNum := 15;
  437.     end;
  438.     case DMAChanMenu.Option of
  439.       0: SoundCard.DRQNum := 0;
  440.       1: SoundCard.DRQNum := 1;
  441.       2: SoundCard.DRQNum := 3;
  442.     end;
  443.     case MixRateMenu.Option of
  444.       0: SoundCard.MixRate := 8000;
  445.       1: SoundCard.MixRate := 12000;
  446.       2: SoundCard.MixRate := 16000;
  447.       3: SoundCard.MixRate := 20000;
  448.       4: SoundCard.MixRate := 22000;
  449.       5: SoundCard.MixRate := 28000;
  450.       6: SoundCard.MixRate := 36000;
  451.       7: SoundCard.MixRate := 44100;
  452.     end;
  453.  
  454.     if (SoundCard.ID = ID_SB) or (SoundCard.ID = ID_SBPro) then begin
  455.       if SoundCard.MixRate >= 22050 then SoundCard.MixRate := 22050;
  456.     end;
  457.  
  458.     {$I-}
  459.     Assign(SoundFile,'SOUND.CFG');
  460.     Rewrite(SoundFile,1);
  461.     BlockWrite(SoundFile,SoundCard,sizeof(SoundCard));
  462.     Close(SoundFile);
  463.     {$I+}
  464.  
  465.     if IOResult <> 0 then writeln('Error saving SOUND.CFG file.')
  466.     else writeln('Setup file saved.');
  467.   end
  468.   else begin
  469.     writeln('Setup aborted.');
  470.   end;
  471. end.
  472.